package com.dai.zhenfujin.my.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dai.zhenfujin.R;
import com.dai.zhenfujin.my.bean.AccountBean;
import com.dai.zhenfujin.utils.UIUtils;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

public class AccountAdapter extends BaseAdapter {

    private Context context;
    private List<AccountBean.TradeListBean> beanList;
    private LayoutInflater inflater;
    private AccountBean accountBean;


    public AccountAdapter(Context context, List<AccountBean.TradeListBean> beanList) {
        this.context = context;
        this.beanList = beanList;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return beanList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView == null){
            holder = new AccountAdapter.ViewHolder();
            convertView = inflater.inflate(R.layout.account_listview,null);
            holder.tvServe= (TextView)convertView.findViewById(R.id.account_listview_serve);
            holder.tvTime= (TextView)convertView.findViewById(R.id.account_listview_time);
            holder.tvPrice= (TextView)convertView.findViewById(R.id.account_listview_price);
            holder.iv_head= (CircleImageView)convertView.findViewById(R.id.iv_head);
            holder.account_state = convertView.findViewById(R.id.account_state);

            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }

        AccountBean.TradeListBean bean = beanList.get(position);
        if (bean.getTrade_type().equals("1")){
            holder.tvServe.setText(bean.user_name + "-充值");
            holder.tvPrice.setText( "+" + UIUtils.getamount(bean.getTrade_amount()) + "元");
        }else if(bean.getTrade_type().equals("2")){
            holder.tvServe.setText(bean.user_name + "-消费");
            holder.tvPrice.setText( "-" + UIUtils.getamount(bean.getTrade_amount()) + "元");
        }else if(bean.getTrade_type().equals("3")) {
            holder.tvServe.setText(bean.user_name + "-赠送");
            holder.tvPrice.setText( "+" + UIUtils.getamount(bean.getTrade_amount()) + "元");
        }else if(bean.getTrade_type().equals("4")) {
            holder.tvServe.setText(bean.user_name + "-其他");
            holder.tvPrice.setText( "+" + UIUtils.getamount(bean.getTrade_amount()) + "元");
        }

        if (bean.trade_state == 1){
            holder.account_state.setText("成功");
        }else if(bean.trade_state == 2){
            holder.account_state.setText("失败");
        }else if(bean.trade_state == 3) {
            holder.account_state.setText("待处理");
        }

        holder.tvTime.setText(bean.getTrade_time().substring(0,bean.getTrade_time().length()-2));
      //  viewHolder.item_time.setText(itemList.getCreate_time().substring(0,itemList.getCreate_time().length()-2));
        Glide.with(context).load(bean.getTrade_user_logo()).into(holder.iv_head);

        return convertView;
    }

    class ViewHolder {
        private TextView tvServe,tvTime,tvPrice,account_state;
        private CircleImageView iv_head;
    }
}
